import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/widgets.dart';
import 'package:ls_work/a_yyt/widget/home_my_work_view.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/resources.dart';
import 'package:ls_work/util/ext_utils.dart';
import 'package:ls_work/viewmodel/elder_detail_info_view_model.dart';

import '../util/utils.dart';

class ElderDetailInfoPage extends BaseStatefulMvvmWidget {
  dynamic customerId;

  ElderDetailInfoPage({required this.customerId});

  @override
  State<StatefulWidget> createState() => _ElderDetailInfoState();
}

class _ElderDetailInfoState
    extends BaseMvvmState<ElderDetailInfoViewModel, ElderDetailInfoPage> {
  @override
  Widget? buildLoadingContentView() {
    var detail = viewModel.elderInfo;
    return detail == null
        ? Container()
        : SingleChildScrollView(
            child: Column(
              children: [
                SizedBox(height: 15,),
                Column(
                  children: [
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Hero(tag: '${HttpApi.imageHead}${detail.headimageId}', child: ImageLoad(
                          '${HttpApi.imageHead}${detail.headimageId}',
                          placeholder: getImagePath("none", parent: "assets"),
                          errorImage: getImagePath("none", parent: "assets"),
                          width: 80,
                          height: 80,
                          fit: BoxFit.cover,
                        )).toCircle(borderWidth: 1).onTap(() {
                          showBigImage(context, ['${HttpApi.imageHead}${detail.headimageId}']);
                        }),
                        SizedBox(width: 16,),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            SizedBox(height: 8,),
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                CommonText(detail.name,textSize: 18,fontWeight: FontWeight.bold),
                                SizedBox(width: 12,),
                                CommonText(detail.statusSecondName,textSize: 14,textColor: Colors.white).addToContainer(
                                  decoration: BoxDecoration(
                                    color: Colors.blue,
                                    borderRadius: 30.borderRadius
                                  ),
                                  padding: EdgeInsets.symmetric(horizontal: 10,vertical: 4)
                                )
                              ],
                            ),
                            SizedBox(height: 12,),
                            CommonText('${detail.sexName} | ${detail.age}岁 | ${detail.buildingNo}#${detail.bedNo} | ${detail.nurseLevelName}',textSize: 15,textColor: Colors.grey[700]!),
                            SizedBox(height: 12,),
                            CommonText('生日：${(detail.birthday??"").changeTime(format: ['yyyy','-','mm','-','dd'])}',textSize: 15,textColor: Colors.grey[700]!),
                            SizedBox(height: 12,),
                            CommonText('入住日期：${(detail.intoDate??"").changeTime(format: ['yyyy','-','mm','-','dd'])}',textSize: 15,textColor: Colors.grey[700]!),

                            
                          ],
                        ).setWeight(1)
                      ],
                    ),
                    SizedBox(height: 12,),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Icon(ElderIcons.icon_body_info,size: 13,color: Colors.white,).addToContainer(
                            decoration: BoxDecoration(
                                color: Colors.blue,
                                shape: BoxShape.circle
                            ),
                            padding: EdgeInsets.all(4)
                        ),
                        SizedBox(width: 8,),
                        Text('身体状况：',style: TextStyle(color: Colors.grey[700]!,fontSize: 14),),
                        Text('${detail.healthName??""}',style: TextStyle(color: Colors.grey[700]!,fontSize: 14),).setWeight(1),
                      ],
                    ),
                    SizedBox(height: 8,),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Icon(ElderIcons.icon_avoid,size: 13,color: Colors.white,).addToContainer(
                            decoration: BoxDecoration(
                                color: Colors.blue,
                                shape: BoxShape.circle
                            ),
                            padding: EdgeInsets.all(4)
                        ),
                        SizedBox(width: 8,),
                        Text('忌讳：',style: TextStyle(color: Colors.grey[700]!,fontSize: 14),),
                        Text('${detail.avoidThing??""}',style: TextStyle(color: Colors.grey[700]!,fontSize: 14),).setWeight(1),
                      ],
                    ),
                    SizedBox(height: 8,),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Icon(ElderIcons.icon_disease,size: 13,color: Colors.white,).addToContainer(
                          decoration: BoxDecoration(
                            color: Colors.blue,
                            shape: BoxShape.circle
                          ),
                          padding: EdgeInsets.all(4)
                        ),
                        SizedBox(width: 8,),
                        Text('病史：',style: TextStyle(color: Colors.grey[700]!,fontSize: 14),),
                        Text('${detail.specialDiseaseRemark??""}',style: TextStyle(color: Colors.grey[700]!,fontSize: 14),).setWeight(1),
                      ],
                    )
                  ],
                ).addToContainer(
                    decoration: BoxDecoration(
                        color: Colors.white, borderRadius: 10.borderRadius),
                    padding: EdgeInsets.symmetric(horizontal: 15, vertical: 15),
                    margin: EdgeInsets.symmetric(horizontal: 16,)),
                SizedBox(height: 15,),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(height: 15,),
                    CommonText('紧急联系人',fontWeight: FontWeight.bold),
                    ...(detail.familyList??[]).map((e) {
                      return Row(
                        children: [
                          Icon(ElderIcons.icon_emergency_contacts,size: 35,color: Colors.white,).addToContainer(
                              decoration: BoxDecoration(
                                  color: Colors.blue,
                                  shape: BoxShape.circle
                              ),
                              padding: EdgeInsets.all(4)
                          ),
                          SizedBox(width: 8,),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                children: [
                                  CommonText(e.name),
                                  SizedBox(width: 10,),
                                  CommonText(e.relationshipName,textSize: 14,textColor: Colors.grey[700]!)
                                ],
                              ),
                              SizedBox(height: 5,),
                              CommonText(e.mobile),

                            ],
                          ).setWeight(1),

                          Icon(Icons.phone_forwarded_rounded,color: Colors.white,size: 20,).addToContainer(
                              decoration: BoxDecoration(
                                  shape: BoxShape.circle,
                                  color: Colors.blue
                              ),
                              width: 30,height: 30
                          ).onTap(() {
                            showBottomSelect(context, items: ['拨打电话','发送短信','复制号码'],onSelect: (item){
                              if(item=='拨打电话'){
                                Utils.launchTelURL(e.mobile??"");
                              }
                              if(item=='发送短信'){
                                Utils.launchSmsURL(e.mobile??"");
                              }
                              if(item=='复制号码'){
                                if(!e.mobile.isNullOrEmpty()){
                                  Utils.copyToClipboard(e.mobile??"");
                                  showToast("已复制到剪切板");
                                }
                              }
                            });

                          }),
                        ],
                      ).addToContainer(
                        padding: EdgeInsets.symmetric(vertical: 15)
                      );
                    }).toList().insertWidget(Gaps.line),
                    SizedBox(height: 15,)
                  ],
                ).addToContainer(
                  width: double.infinity,
                    decoration: BoxDecoration(
                        color: Colors.white, borderRadius: 10.borderRadius),
                    padding: EdgeInsets.symmetric(horizontal: 15,),
                    margin: EdgeInsets.symmetric(horizontal: 16)),

                SizedBox(height: 15,),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(height: 15,),
                    CommonText('信息查询',fontWeight: FontWeight.bold),
                    SizedBox(height: 12,),
                    MyWorkView(
                      type: 4,
                      info: detail,
                    ),
                  ],
                ).addToContainer(
                    width: double.infinity,
                    decoration: BoxDecoration(
                        color: Colors.white, borderRadius: 10.borderRadius),
                    padding: EdgeInsets.symmetric(horizontal: 15,),
                    margin: EdgeInsets.symmetric(horizontal: 16)),

                SizedBox(height: 15,),

                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(height: 15,),
                    CommonText('操作',fontWeight: FontWeight.bold),
                    SizedBox(height: 12,),
                    MyWorkView(
                      type: 5,
                      elderNameLike: detail.name,
                      customerId: detail.id!,
                      info: detail,
                    ),
                  ],
                ).addToContainer(
                    width: double.infinity,
                    decoration: BoxDecoration(
                        color: Colors.white, borderRadius: 10.borderRadius),
                    padding: EdgeInsets.symmetric(horizontal: 15,),
                    margin: EdgeInsets.symmetric(horizontal: 16)),
              ],
            ),
          );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: AppBar(
        title: Text("长者信息"),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  ElderDetailInfoViewModel createViewModel() {
    return ElderDetailInfoViewModel(context, customerId: widget.customerId);
  }

  @override
  void onRetryClick() {
  }
}
